def decodeString(s):
    def decode(i):
        res=""
        num=0
        while(i<len(s)):
            if "0" <= s[i] <= "9":
                num = num * 10 + int(s[i])
            elif s[i] == '[':
                i,tmp = decode(i + 1)
                res = res + num * tmp
                num = 0
            elif s[i] == ']':
                return i, res
            else:
                res = res + s[i]
            i=i+1
        return res
    return decode(0)
print(decodeString('3[ab]5[b]'))